<template>
  <div class="Internal">
    <div class="first">
      <div class="first-top">
        <div class="top-list" v-for="(item, index) in 3" :key="index">
          <div class="list-title">
            {{ index == 0 ? "姓名" : index == 1 ? "证件号" : "商户号" }}
          </div>
          <div class="list-input">
            <el-input
              v-if="index == 0"
              v-model="firstName"
              clearable
              placeholder="请输入姓名"
            ></el-input>
            <el-input
              v-if="index == 1"
              v-model="firstCertificate"
              clearable
              placeholder="请输入证件号"
            ></el-input>
            <el-input
              v-if="index == 2"
              v-model="firstCommercial"
              clearable
              placeholder="请输入商户号"
            ></el-input>
          </div>
        </div>

        <div class="top-button">
          <div
            class="button"
            v-for="(item, index) in 2"
            :key="index"
            @click="walletFunction(index)"
          >
            {{ index == 0 ? "搜索" : "重置" }}
          </div>
        </div>
      </div>

      <div class="first-center">
        <div
          class="center"
          v-for="(item, index) in 1"
          :key="index"
          :style="{
            background: index == 1 ? '#A9A9A9' : '',
          }"
          @click="walletMet(index)"
        >
          <img
            class="center-img"
            :src="
              index == 0
                ? require('../../assets/index/icon-7.png')
                : require('../../assets/index/icon-9.png')
            "
            alt=""
          />
          <div class="center-title">
            {{ index == 0 ? "替换成平台钱包" : "删除" }}
          </div>
        </div>
      </div>

      <div class="first-bottom">
        <img class="bottom-img" src="../../assets/index/icon-10.png" alt="" />
        <div class="bottom-title">已选择{{ multipleSelectionTotal }}项</div>
        <div class="bottom-title">
          服务调用总计：{{ multipleSelectionPrice }}元
        </div>
        <div
          class="bottom-title"
          style="color: #2588fa; text-decoration: underline; cursor: pointer"
          @click.stop="emptyStop"
        >
          清空
        </div>
      </div>
    </div>

    <div class="second">
      <div class="second-table">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          :header-cell-style="{
            color: '#949494',
            backgroundColor: '#F9F9F9',
          }"
          @sort-change="sortChange"
        >
          <!-- 自定义暂无数据 -->
          <template slot="empty">
            <div class="empty-block">
              <img
                class="empty-block-img"
                src="../../assets/common/common-empty.png"
              />
              <div class="empty-block-text">暂无数据～</div>
            </div>
          </template>
          <el-table-column
            type="selection"
            width="100"
            align="center"
          ></el-table-column>
          <el-table-column prop="id" label="钱包ID" width="110" align="center">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="110" align="center">
          </el-table-column>
          <el-table-column
            prop="certNo"
            label="证件号"
            width="200"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="phone" label="电话" width="200" align="center">
          </el-table-column>
          <el-table-column
            prop="merchantNo"
            label="商户号"
            width="180"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="" label="余额" width="200" align="center">
            <template slot-scope="scope"> ￥{{ scope.row.money }} </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            sortable
            width="300"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="" label="操作" width="250" align="center">
            <template slot-scope="scope">
              <div class="operation">
                <div
                  class="operation-list"
                  @click="walletOperation(0, scope.row)"
                >
                  内部user id
                </div>
                <div
                  class="operation-list"
                  style="color: #f58f17"
                  @click="walletOperation(1, scope.row)"
                >
                  银行卡
                </div>
                <div
                  class="operation-list"
                  style="color: #0ac1c7"
                  @click="walletOperation(2, scope.row)"
                >
                  明细
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="second-pagination">
        <div class="pagination-left">共{{ totalNum }}条数据</div>

        <div class="pagination-right">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="10"
            layout="sizes, prev, pager, next, jumper"
            :total="totalNum"
          ></el-pagination>
        </div>
      </div>
    </div>

    <!--提示-->
    <div class="hint">
      <el-dialog title="" :visible.sync="hintDialogVisible1" round>
        <div class="hint-block">
          <img class="block-img" src="../../assets/common/common-warning.png" />
          <div class="block-title">
            确定将选中的乡米网钱包用户同步到平台吗？同步后平台商户可向该钱包用户分账，注意风险控制!
          </div>
          <div class="block-bottom">
            <div
              class="bottom"
              v-for="(item, index) in 2"
              :key="index"
              @click="hintFunction1(index)"
            >
              {{ index == 0 ? "取消" : "确认" }}
            </div>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import Bus from "../../utils/bus";
import {
  getUserInfoWallet,
  postsetWalletOutsideWallet,
} from "../../api/wallet";

export default {
  data() {
    return {
      ///-----------第一区域
      firstName: "",
      firstCertificate: "",
      firstCommercial: "",
      //------------第二区域
      tableData: [],
      multipleSelection: [],
      multipleSelectionTotal: 0,
      multipleSelectionPrice: 0,
      totalNum: 0,
      page: 1,
      limit: 10,
      loading: false,
      hintDialogVisible1: false,
      walletShow: false,
    };
  },
  created() {
    setTimeout(() => {
      this.walletShow = this.$store.state.pageFunctionShow;
    }, 1000);
    this.getUserInfoWalletMet();
  },
  methods: {
    // 钱包
    getUserInfoWalletMet() {
      let params = {
        name: this.firstName,
        certNo: this.firstCertificate,
        merchantNo: this.firstCommercial,
        type: 1, // 外部 0  内部 1
        pageNo: this.page,
        pageSize: this.limit,
      };

      getUserInfoWallet(params).then((res) => {
        if (res.resultStatus == true) {
          this.tableData = res.resultData.list;
          this.totalNum = res.resultData.totalNum;
          this.loading = false;
        }
      });
    },
    walletFunction(index) {
      if (index == 0) {
      } else {
        this.firstName = "";
        this.firstCertificate = "";
        this.firstCommercial = "";
        this.multipleSelectionTotal = 0;
      }

      this.getUserInfoWalletMet();
    },

    // 表格区域点击选中 勾选对应的
    handleSelectionChange(val) {
      let price = 0;

      val.forEach((item, index) => {
        price = Number(price) + Number(item.money);
      });

      this.multipleSelectionTotal = val.length;
      this.multipleSelectionPrice = price;
      this.multipleSelection = val;
    },
    emptyStop() {
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
      this.getUserInfoWalletMet();
    },
    // 点击监听排序
    sortChange(e) {
      console.log("dianj ", e);
    },
    walletMet(index) {
      if (this.walletShow == false) {
        this.$message.error('暂无权限!')
        return;
      }

      if (index == 0) {
        if (this.multipleSelection.length == 0) {
          this.$message.warning("请先勾选对应的平台用户！");
          return;
        }

        this.hintDialogVisible1 = true;
      }
    },

    walletOperation(index, item) {
      if (this.walletShow == false) {
        this.$message.error('暂无权限!')
        return;
      }

      if (index == 0) {
        let obj = {
          merchantNo: item.merchantNo,
        };
        Bus.$emit("log", "internalWalletUserid", obj);
      } else if (index == 1) {
        let obj = {
          merchantNo: item.merchantNo,
        };
        Bus.$emit("log", "internalWalletBank", obj);
      } else {
        let obj = {
          merchantNo: item.merchantNo,
        };
        Bus.$emit("log", "internalWalletDetails", obj);
      }
    },

    //----------------------------------------------------------
    hintFunction1(index) {
      debugger
      if (index == 0) {
        this.hintDialogVisible1 = false;
      } else {
        let array = [];
        this.multipleSelection.forEach((item, index) => {
          array.push(item.merchantNo);
        });

        let str = array.join(";");

        let params = {
          merchantNo: str,
        };

        postsetWalletOutsideWallet(params).then((res) => {
          if (res.resultStatus == true) {
            this.getUserInfoWalletMet();
            this.hintDialogVisible1 = false;
            this.$message.success("替换成功！");
          }
        });
      }
    },
    //  查询当前页码多少条
    handleSizeChange(val) {
      this.limit = val;
    },
    //  查询当前页
    handleCurrentChange(val) {
      this.page = val;
    },
  },
};
</script>

<style lang="less" scoped>
.Internal {
  .first {
    .first-top {
      display: flex;
      align-items: center;
      .top-list {
        display: flex;
        align-items: center;
        margin-right: 12px;

        .list-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #757575;
          margin-right: 12px;
        }

        .list-input {
          /deep/ .el-input__inner {
            width: 174px;
            height: 38px;
            background: #ffffff;
            border-radius: 4px;
          }
        }
      }

      .top-button {
        display: flex;
        align-items: center;

        .button {
          width: 66px;
          height: 38px;
          background: #2588fa;
          border-radius: 4px;
          display: flex;
          align-items: center;
          justify-content: center;

          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #ffffff;
          cursor: pointer;
          border: 1px solid #2588fa;
        }

        .button:last-child {
          background: #ffffff;
          color: #949494;
          margin-left: 12px;
          border: 1px solid #dedede;
        }
      }
    }

    .first-center {
      margin-top: 15px;
      display: flex;
      align-items: center;

      .center {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-right: 10px;
        height: 38px;
        padding: 0 14px;
        box-sizing: border-box;
        background: #2588fa;
        border-radius: 4px;
        cursor: pointer;

        .center-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #ffffff;
        }

        .center-img {
          width: 12px;
          height: 12px;
          margin-right: 8px;
        }
      }
    }

    .first-bottom {
      margin-top: 16px;
      display: flex;
      align-items: center;
      height: 38px;
      background: #edf5ff;
      border-radius: 4px;
      border: 1px solid #aed4ff;
      padding: 0 16px;
      box-sizing: border-box;

      .bottom-img {
        width: 14px;
        height: 14px;
        margin-right: 11px;
      }

      .bottom-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #292929;
        margin-right: 17px;
      }
    }
  }

  .second {
    margin-top: 16px;
    .second-table {
      /deep/ .el-table thead {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #949494;
      }

      /deep/ .el-table tr {
        height: 46px;
      }

      /deep/ .el-table__empty-text {
        line-height: 0;
      }

      /deep/ .el-table .el-table__cell {
        padding: 0;
      }

      .empty-block {
        margin-top: 62px;
        padding-bottom: 40px;

        .empty-block-img {
          width: 130px;
          height: 130px;
          margin: 0 auto;
        }

        .empty-block-text {
          font-size: 12px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          margin-top: 10px;
          height: 17px;
          line-height: 17px;
        }
      }

      .operation {
        display: flex;
        align-items: center;
        justify-content: center;

        .operation-list {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #2588fa;
          text-decoration: underline;
          cursor: pointer;
          margin-right: 16px;
        }
      }
    }

    .second-pagination {
      height: 75px;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .pagination-left {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 15px;
        color: #949494;
      }

      .pagination-right {
        /deep/ .el-pagination .btn-prev {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
          margin-right: 8px;
        }

        /deep/ .el-pagination .btn-next {
          padding: 0;
          width: 30px;
          height: 30px;
          background: #f4f5f9;
          border-radius: 2px;
          border: 1px solid #d9d9d9;
        }

        /deep/ .el-pager li {
          padding: 0;
          width: 30px;
          height: 30px;
          border-radius: 2px;
          background: #f4f5f9;
          border: 1px solid #d9d9d9;
          line-height: 30px;
          margin-right: 8px;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 15px;
          color: #949494;
        }

        /deep/ .el-pager li.active {
          background: #2588fa;
          color: #ffffff;
        }

        /deep/ .el-input--mini .el-input__inner {
          height: 30px;
          background: #f4f5f9;
        }

        /deep/ .el-input__inner {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: rgba(0, 0, 0, 0.65);
        }
      }
    }
  }

  .hint {
    /deep/ .el-dialog {
      width: 350px;
      height: 270px;
      background: #ffffff;
      border-radius: 6px;
    }

    /deep/ .el-dialog__body {
      padding: 0;
    }

    .hint-block {
      padding: 24px;
      box-sizing: border-box;

      .block-img {
        width: 48px;
        height: 48px;
        margin: 0 auto;
        border-radius: 50%;
        display: flex;
      }

      .block-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #555555;
        margin-top: 16px;
        text-align: center;
      }

      .block-text {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 14px;
        color: #949494;
        text-align: center;
      }

      .block-bottom {
        padding: 0 23px;
        box-sizing: border-box;
        margin-top: 40px;
        display: flex;
        align-items: center;
        justify-content: center;

        .bottom {
          cursor: pointer;
          width: 80px;
          height: 38px;
          background: #ffffff;
          border-radius: 4px;
          border: 1px solid #dedede;
          display: flex;
          justify-content: center;
          align-items: center;

          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #949494;
        }

        .bottom:last-child {
          background: #2588fa;
          color: #ffffff;
          margin-left: 20px;
          border: 1px solid #2588fa;
        }
      }
    }
  }
}
</style>
